<style>
    .layui-form-label {
        width: 100px;
    }
    .layui-input-block {
        margin-left: 130px;
    }
    .import {
        opacity: 0;
        position: absolute;
        width: 69px;
        height: 38px;
        margin-left: -10px;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">物料编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编号"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">规格码：</label>
                                    <div class="layui-input-inline">
                                        <input name="oldSpecCode" class="layui-input" type="text" placeholder="请输入规格码"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">机台：</label>
                                    <div class="layui-input-inline">
                                        <input name="deviceCode" class="layui-input" type="text" placeholder="请输入机台"/>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>查询</button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                                    <button id="useInventoryProductExport" class="layui-btn icon-btn"><i class="layui-icon">&#xe67d;</i>导出</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
<!--                <div class="lay-btn-rows">-->
<!--                    <div class="lay-btn-box">-->
<!--                        <div class="lay-btn-lt">-->
<!--                            <button id="fromLocalWarehouseBtnImport" class="layui-btn icon-btn color-reseda">-->
<!--                                <input id="uploaderInput" type="file" name="file" class="import" accept=".xls,.xlsx"/>导入-->
<!--                            </button>-->
<!--                            <button id="returnBtn" class="layui-btn icon-btn color-reseda">批量还刀-->
<!--                            </button>-->
<!--                        </div>-->
<!--                        <div class="lay-btn-rt">-->
<!--                            <button id="fromLocalWarehouseBtnTemplate" class="layui-btn icon-btn color-green">模板下载-->
<!--                            </button>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                </div>-->
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="userInventoryProductTable" lay-filter="userInventoryProductTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="userInventoryProductTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
    <!--
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="inventorySpace">库存分布</a>

    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    -->
</script>

<script type="text/html" id="inventoryProductTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
    <!--
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    -->
</script>

<script type="text/html" id="useInventoryProductTable4ReturnTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <!--
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>

    -->
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="storageInventoryInoutForm">
    <form lay-filter="storageInventoryInoutForm" class="layui-form model-form">
        <input name="id" type="hidden"/>

        <div class="layui-form-item">
            <label class="layui-form-label">物料图片</label>
            <div class="layui-input-block">
                <img id="skuPic" src="" style="width: 100px;height: 100px">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">物料名称</label>
            <div class="layui-input-block">
                <input name="skuName" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">物料编号</label>
            <div class="layui-input-block">
                <input name="skuCode" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">原规格</label>
            <div class="layui-input-block">
                <input name="skuSpecOld" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">品牌</label>
            <div class="layui-input-block">
                <input name="productBrandName" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">在用数</label>
            <div class="layui-input-block">
                <input name="quantity" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">使用机台</label>
            <div class="layui-input-block">
                <input name="deviceCode" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">领用人</label>
            <div class="layui-input-block">
                <input name="creatorName" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">领用时间</label>
            <div class="layui-input-block">
                <input name="createTime" placeholder="" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
    </form>
</script>

<script type="text/html" id="inventorySpaceTab">

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">

                            <label class="layui-form-label w-auto">物料编号：</label>
                            <div class="layui-input-inline mr0">
                                <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编号"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn" lay-filter="formSubSearchLog" lay-submit><i class="layui-icon">&#xe615;</i>搜索</button>
                            <!--
                            <button id="storageInventoryInoutBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                            -->
                        </div>
                    </div>
                </div>
                <!-- 表格 -->
                <table class="layui-table" id="inventoryProductTable" lay-filter="inventoryProductTable"></table>
                <br>
                <table class="layui-table" id="inventorySpaceTable" lay-filter="inventorySpaceTable"></table>
            </div>
        </div>
    </div>

</script>


<script type="text/html" id="returnOrderTable">

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">

                <!-- 表格 -->
                <table class="layui-table" id="useInventoryProductTable4Return" lay-filter="useInventoryProductTable4Return"></table>


            </div>
        </div>
    </div>


    <form id="returnOrderForm" lay-filter="returnOrderForm" class="layui-form model-form">

        <div align="center" >
            <div class="layui-form-item text-right saveCancelBtn" >
                <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
                <button class="layui-btn" lay-filter="returnOrderBtnSubmit" lay-submit>提交</button>
            </div>
        </div>
        <br>
    </form>
</script>


<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var currentPageData=[];
        var currentPage;
        var totalPage;
        // 渲染表格
        var insTb = table.render({
            elem: '#userInventoryProductTable',
            url: config.base + 'enterprisecab/cabinet/admin/useInventoryKnife/list',
            page: true,
            cellMinWidth: 100,
            // limits:[5,10],
            // limit:5,
            cols: [[
                {type: 'checkbox'}
                // ,{field: 'id', sort: true, title: 'id'}
                ,{field: 'skuPic', sort: false, title: '物料图片',templet:function (d) {
                        if(d.skuPic){
                            return '<img src="'+ d.skuPic +'" style="height: 20px;"/>';
                        }
                        return '';
                    }}
                ,{field: 'labelCode', sort: false, title: '刀具编号'}
                ,{field: 'skuName', sort: true, title: '物料名称'}
                ,{field: 'skuCode', sort: true, title: '物料编号'}
                ,{field: 'skuSpecOld', sort: false, title: '规格码'}
                ,{field: 'skuSpec', sort: false, title: '规格'}
                ,{field: 'productBrandName', sort: false, title: '品牌'}
                ,{field: 'quantity', sort: false, title: '在用数',templet:function (d) {
                        if(d.quantity<0){
                            return d.quantity*-1;
                        }
                        return  d.quantity;
                    }}
                ,{field: 'remainingTime', title: '寿命'}
                ,{field: 'deviceCode', sort: false, title: '使用机台'}
                ,{field: 'creatorName', sort: true, title: '领用人'}
                ,{field: 'createTime',  sort: true, title: '领用时间'}
                ,{align: 'center', toolbar: '#userInventoryProductTableBar', title: '操作', width: 200}
            ]],
            done: function (res, curr, count) {
                currentPage=curr;
                totalPage=Math.ceil(parseInt(count)/insTb.config.page.limit);
                // if(parseInt(count)%insTb.config.page.limit!=0){
                //     totalPage+=1;
                // }
                currentPageData=res.data;
                var isCheckAll=true;
                for(var k=0;k<res.data.length;k++){
                    res.data[k].LAY_CHECKED = true;
                    var index= res.data[k]['LAY_TABLE_INDEX'];
                    res.data[k].index=index;
                    var checkbox = $('#'+'userInventoryProductTable'+'').next().find('tr[data-index=' + index + '] input[type="checkbox"]');
                    if(checkedMap.get(res.data[k].id)){
                        checkbox.prop('checked', true).next().addClass('layui-form-checked');
                    }else{
                        isCheckAll=false;
                    }

                }
                if(res.data.length==0){
                    isCheckAll=false;
                }
                if(isCheckAll){
                    $('[lay-filter="layTableAllChoose"]').prop('checked', true).next().addClass('layui-form-checked');
                }

                //移除按钮

                var menuButton = config.getMenuButton(location.hash);
                if(menuButton.indexOf("搜索") == -1){
                    $('.layui-form.toolbar').remove();
                }
                if(menuButton.indexOf("修改") == -1){
                    $("[lay-event='edit']").remove();
                }
                if(menuButton.indexOf("删除") == -1){
                    $("[lay-event='del']").remove();
                }
            }
        });


        // 重置搜索
        form.on('submit(resets)', data => {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        //导入excel
        $('#uploaderInput').on("change", function (e) {
            layer.load(2);
            var formData = new FormData();
            var files = e.target.files;
            let that = $(this);
            formData.append("file", files[0]);
            formData.append("name", files[0].name);//这个地方可以传递多个参数
            $.ajax({
                url: config.base + 'enterprisecab/cabinet/admin/useInventoryUser/importExcel',
                data: formData,
                headers: {Authorization: 'Bearer ' + config.getToken()},
                type: "POST",
                processData: false,
                contentType: false,
                success: function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        // table.reload('humanResourcesTable');
                        layer.closeAll('page');
                        setTimeout(_ => {
                            location.reload()
                        }, 1000);
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                    that.val('');
                }
            });

        })
        // 模板下载
        $('#fromLocalWarehouseBtnTemplate').click(function () {
            window.location.href = config.base + "enterprisecab/cabinet/admin/useInventoryUser/template";
        });
        // 工具条点击事件
        table.on('tool(userInventoryProductTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                showEditModel(data);
            } else if (obj.event === 'del') { // 删除
                doDelete(obj);
            }else if(obj.event=='detail'){
                showEditModel(data);
            }else if(obj.event=='inventorySpace'){
                showInventorySpaceModel(data)
            }
        });

        //监听排序
        table.on('sort(userInventoryProductTable)', function(obj){
            table.reload('userInventoryProductTable', {
                initSort: obj
                ,where: {
                    sort: obj.field
                    ,order: obj.type
                }
            });
        });


        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field,page: {curr: 1}},'data');
        });

        var checkedMap=new Map();
        var checkedData=[];
        table.on('checkbox(userInventoryProductTable)', function(obj){
            var data = obj.data;
            if(obj.type=='all'){
                if(obj.checked){
                    var checkStatus = table.checkStatus('userInventoryProductTable')
                    var checkedAllData = checkStatus.data;
                    checkedAllData.forEach(item=> {

                            if (checkedMap.get(item.id) == undefined) {
                                checkedData.push(item);
                            }
                            checkedMap.set(item.id,item.id);


                    })


                }else{
                    currentPageData.forEach(item=>{
                        if(checkedMap.get(item.id)!=undefined){
                            checkedData=checkedData.filter(item2=>{
                                if(item.id==item2.id){
                                    return false;
                                }
                                return  true;
                            })
                        }
                        checkedMap.delete(item.id);

                    })
                }
            }else{
                if(obj.checked){
                    if (checkedMap.get(data.id) == undefined) {
                        checkedData.push(data);
                    }
                    checkedMap.set(data.id,data.id);
                }else{
                    if(checkedMap.get(data.id)!=undefined){
                        checkedData=checkedData.filter(item=>{
                            if(item.id==data.id){
                                return false;
                            }
                            return  true;
                        })
                    }
                    checkedMap.delete(data.id);
                }
                var isAllChecked=true;
                currentPageData.forEach(item=>{

                        if(checkedMap.get(item.id)==undefined){
                            isAllChecked=false;
                        }


                })
                if(isAllChecked){
                    $('[lay-filter="layTableAllChoose"]').prop('checked', true).next().addClass('layui-form-checked');
                }else{
                    $('[lay-filter="layTableAllChoose"]').prop('checked', false).next().removeClass('layui-form-checked');
                }
            }

        });


        $('#returnBtn').click(function () {
            if(checkedData.length==0){
                layer.msg('请选择在用刀具', {icon: 2})
                return;
            }
            showEditGenOrderModel();
        });

        function showCheckedDataTable(data,curr){
            var insTb = table.render({
                elem: '#useInventoryProductTable4Return',
                data: data,
                page: {
                    curr:curr==undefined?1:curr
                },
                // limits:[5,10],
                // limit:5,
                cellMinWidth: 100,
                // curr:curr==undefined?1:curr,
                cols: [[
                    {type: 'numbers',title:'序号'}
                    // ,{field: 'id', sort: true, title: 'id'}
                    ,{field: 'skuPic', sort: true, title: '物料图片',templet:function (d) {
                            if(d.skuPic){
                                return '<img src="'+ d.skuPic +'" style="height: 20px;"/>';
                            }
                            return '';
                        }}
                    ,{field: 'skuName', sort: true, title: '物料名称'}
                    ,{field: 'skuCode', sort: true, title: '物料编号'}

                    ,{field: 'skuSpecOld', sort: true, title: '规格码'}
                    ,{field: 'skuSpec', sort: true, title: '规格'}
                    ,{field: 'productBrandName', sort: true, title: '品牌'}
                    ,{field: 'quantity', sort: true, title: '在用数',templet:function (d) {
                            if(d.quantity<0){
                                return d.quantity*-1;
                            }
                            return  d.quantity;
                        }}
                    ,{field: 'unitName', sort: true, title: '单位'}
                    ,{field: 'deviceCode', sort: true, title: '使用机台'}
                    ,{field: 'creatorName', sort: true, title: '领用人'}
                    ,{field: 'createTime', sort: true, title: '领用时间'}
                    // ,{field: 'isGenOrder', sort: true, title: '是否已生成订单',templet:function (d) {
                    //         if(d.isGenOrder){
                    //             return '是'
                    //         }
                    //         return '否';
                    //     }}
                    ,{align: 'center', toolbar: '#useInventoryProductTable4ReturnTableBar', title: '操作', width: 200}
                ]],
                done: function (res, curr, count) {
                    // currentPageData=res.data;
                    //移除按钮

                    // var menuButton = config.getMenuButton(location.hash);
                    // if(menuButton.indexOf("搜索") == -1){
                    //     $('.layui-form.toolbar').remove();
                    // }
                    // if(menuButton.indexOf("修改") == -1){
                    //     $("[lay-event='edit']").remove();
                    // }
                    // if(menuButton.indexOf("删除") == -1){
                    //     $("[lay-event='del']").remove();
                    // }
                }
            });

            // 工具条点击事件
            table.on('tool(useInventoryProductTable4Return)', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit') { //修改
                    showEditModel(data);
                } else if (obj.event === 'del') { // 删除
                    doDelete(obj);
                }else if(obj.event=='detail'){
                    data.eventType='detail'
                    showEditModel(data);
                }else if(obj.event=='del'){

                }

            });

            //监听排序
            table.on('sort(useInventoryProductTable4Return)', function(obj){
                table.reload('useInventoryProductTable4Return', {
                    initSort: obj
                    ,where: {
                        sort: obj.field
                        ,order: obj.type
                    }
                });
            });

            function doDelete(obj) {
                layer.confirm('确定要删除吗？', {
                    offset: '65px',
                    skin: 'layui-layer-admin'
                }, function (i) {
                    layer.close(i);
                    layer.msg('删除成功', {icon: 1});
                    obj.del();
                    var data=obj.data;
                    var index=data.index;
                    var checkbox = $('#'+'userInventoryProductTable'+'').next().find('tr[data-index=' + index + '] input[type="checkbox"]');
                    checkbox.prop('checked', false).next().removeClass('layui-form-checked');
                    $('[lay-filter="layTableAllChoose"]').prop('checked', false).next().removeClass('layui-form-checked');
                    checkedData=checkedData.filter(item=>{
                        if(item.id==data.id){
                            return false;
                        }
                        return true;
                    })
                    checkedMap.delete(data.id);
                    var count=insTb.config.page.count-1;
                    var curr=insTb.config.page.curr;
                    var limit=insTb.config.limit;
                    var pages=Math.floor(count/limit);
                    if(count%limit!=0){
                        pages+=1;
                    }
                    if(curr>pages){
                        curr=pages-1;
                        if (curr<0){
                            curr=1;
                        }
                    }
                    showCheckedDataTable(checkedData,curr);
                });
            }
        }



        function showEditGenOrderModel(data) {

            admin.open({
                type: 1,
                area: '1480px',
                offset: '65px',
                title: '批量还刀',
                content: $('#returnOrderTable').html(),
                success: function () {
                    showCheckedDataTable(checkedData);


                    form.on('submit(returnOrderBtnSubmit)', function (d) {
                        if(checkedData.length==0){
                            layer.msg('木有可提交的在用刀具数据', {icon: 2})
                            return false;
                        }
                        layer.load(2);

                        admin.req('enterprisecab/cabinet/admin/useInventoryInoutDetail/inventoryOut', JSON.stringify(checkedData), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                var curr=currentPage;
                                if (currentPage=totalPage){
                                    curr=currentPage-1
                                    if(curr<0){
                                        curr=1;
                                    }
                                }
                                insTb.reload({where: d.field,page: {curr:curr}},'data');
                                // table.reload('userInventoryProductTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST', true, 'application/json; charset=utf-8');
                        checkedMap=new Map();
                        checkedData=[];
                        return false;
                    });



                }
            });
        }

        // 添加按钮点击事件
        $('#storageInventoryInoutBtnAdd').click(function () {
            showEditModel();
        });

        function getInventorySpace(data){
            var insTb = table.render({
                elem: '#inventorySpaceTable',
                url: config.base + 'enterprisecab/cabinet/admin/cellInventorySpace/list?skuCode='+data.skuCode,
                page: true,
                cellMinWidth: 100,
                cols: [[
                    {type: 'numbers'}

                    ,{field: 'spaceCode', sort: true, title: '货道编号'}
                    ,{field: 'cabCode', sort: true, title: '柜子编号'}

                    ,{field: 'skuName', sort: true, title: '物料名称'}
                    ,{field: 'skuCode', sort: true, title: '物料编号'}
                    ,{field: 'quantity', sort: true, title: '库存'}
                    ,{field: 'quantityMax', sort: true, title: '最大库存'}
                    ,{field: 'unitName', sort: true, title: '单位'}

                    // ,{align: 'center', toolbar: '#userInventoryProductTableBar', title: '操作', width: 200}
                ]],
                done: function (res, curr, count) {
                    //移除按钮
                    var menuButton = config.getMenuButton(location.hash);
                    if(menuButton.indexOf("搜索") == -1){
                        $('.layui-form.toolbar').remove();
                    }
                    if(menuButton.indexOf("修改") == -1){
                        $("[lay-event='edit']").remove();
                    }
                    if(menuButton.indexOf("删除") == -1){
                        $("[lay-event='del']").remove();
                    }
                }
            });

            // 工具条点击事件
            table.on('tool(inventorySpaceTable)', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit') { //修改
                    showEditModel(data);
                } else if (obj.event === 'del') { // 删除
                    doDelete(obj);
                }
            });

            //监听排序
            table.on('sort(inventorySpaceTable)', function(obj){
                table.reload('inventorySpaceTable', {
                    initSort: obj
                    ,where: {
                        sort: obj.field
                        ,order: obj.type
                    }
                });
            });

            // 搜索
            form.on('submit(formSubSearchLog)', function (data) {
                insTb.reload({where: data.field,page: {curr: 1}},'data');
            });
        }

        function getInventoryProduct(data){
            var insTb = table.render({
                elem: '#inventoryProductTable',
                url: config.base + 'enterprisecab/cabinet/admin/cellInventoryProduct/list?skuCode='+data.skuCode,
                page: false,
                cellMinWidth: 100,
                cols: [[
                    {type: 'numbers'}

                    ,{field: 'skuName', sort: true, title: '物料名称'}
                    ,{field: 'skuCode', sort: true, title: '物料编号'}
                    ,{field: 'productBrandName', sort: true, title: '品牌'}
                    ,{field: 'quantity', sort: true, title: '在用数'}
                    // ,{field: 'status', sort: true, title: '库存状态',templet:function (d) {
                    //         return '';
                    //     }}
                    // ,{field: 'no', sort: true, title: 'no'}
                    // ,{field: 'day', sort: true, title: 'day'}
                    // ,{field: 'operationTypeDesc', sort: true, title: '操作类型'}
                    // ,{field: 'businessTypeDesc', sort: true, title: '业务类型'}
                    // ,{field: 'statusDesc', sort: true, title: '状态'}
                    // ,{field: 'checkTime', sort: true, title: '盘验时间'}
                    // ,{field: 'checkUserId', sort: true, title: '盘验人id'}
                    // ,{field: 'checkUserName', sort: true, title: '盘验人'}
                    // ,{field: 'notifyTime', sort: true, title: '通知时间'}
                    // ,{field: 'notifyUserId', sort: true, title: '通知人'}
                    // ,{field: 'notifyUserName', sort: true, title: '通知人'}
                    // ,{field: 'takeUserId', sort: true, title: '回收人id'}
                    // ,{field: 'takeUserName', sort: true, title: '回收人'}
                    // ,{field: 'takeTime', sort: true, title: '回收时间'}
                    // ,{field: 'inoutId', sort: true, title: '暂存柜存刀id'}
                    // ,{field: 'cabId', sort: true, title: '柜子id'}
                    // ,{field: 'skuId', sort: true, title: 'sku id'}
                    // ,{field: 'companyId', sort: true, title: '企业id'}
                    // ,{field: 'spaceId', sort: true, title: '货道id'}
                    // ,{field: 'operationTypeDesc', sort: true, title: '操作类型'}
                    // ,{field: 'businessTypeDesc', sort: true, title: '业务类型'}
                    // ,{field: 'quantityCurrent', sort: true, title: '当前库存'}
                    // ,{field: 'quantityAfter', sort: true, title: '变动后库存'}

                    ,{align: 'center', toolbar: '#inventoryProductTableBar', title: '操作', width: 200}
                ]],
                done: function (res, curr, count) {
                    //移除按钮
                    var menuButton = config.getMenuButton(location.hash);
                    if(menuButton.indexOf("搜索") == -1){
                        $('.layui-form.toolbar').remove();
                    }
                    if(menuButton.indexOf("修改") == -1){
                        $("[lay-event='edit']").remove();
                    }
                    if(menuButton.indexOf("删除") == -1){
                        $("[lay-event='del']").remove();
                    }
                }
            });

            // 工具条点击事件
            table.on('tool(inventoryProductTable)', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit') { //修改
                    showEditModel(data);
                } else if (obj.event === 'del') { // 删除
                    doDelete(obj);
                }else if(obj.event=='detail'){
                    showEditModel(data)
                }
            });
        }

        function showInventorySpaceModel(data){
            admin.open({
                type: 1,
                area: '1280px',
                offset: '65px',
                title: '库存分布',
                content: $('#inventorySpaceTab').html(),
                success: function () {
                    getInventoryProduct(data)
                    getInventorySpace(data);

                }
            })
        }



        // 显示编辑弹窗
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: '1280px',
                offset: '65px',
                title: '详情',
                content: $('#storageInventoryInoutForm').html(),
                success: function () {
                    if (data){
                        var option = $("form select[name='operationType']").find("option");
                        layui.each(option, function(index, item){
                            if(data.operationType  == item.text){
                                data.operationType = item.value;
                            }
                        });
                    }

                    if (data){
                        var option = $("form select[name='businessType']").find("option");
                        layui.each(option, function(index, item){
                            if(data.businessType  == item.text){
                                data.businessType = item.value;
                            }
                        });
                    }

                    if (data){
                        var option = $("form select[name='status']").find("option");
                        layui.each(option, function(index, item){
                            if(data.status  == item.text){
                                data.status = item.value;
                            }
                        });
                    }
                    if(data.skuPic){
                        $("#skuPic").attr('src',data.skuPic);
                    }
                    $(".model-form input").css("border","none")
                    $(".model-form input").attr('readonly',true);
                    form.val('storageInventoryInoutForm', data);
                    // 表单提交事件
                    form.on('submit(storageInventoryInoutFormSubmit)', function (d) {
                        layer.load(2);
                        admin.req(data ? 'enterprisecab/cabinet/admin/storageInventoryInout/update' : 'enterprisecab/cabinet/admin/storageInventoryInout/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('userInventoryProductTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST');
                        return false;
                    });
                }
            });
        }

        // 删除
        function doDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprisecab/cabinet/admin/storageInventoryInout/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        // 导出excel
        /*$('#storageInventoryInoutBtnExport').click(function () {
            var checkRows = table.checkStatus('userInventoryProductTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });*/

        //查询企业信息
        var enterpriseInfo;
        admin.req('enterprise/system/admin/enterpricceId/getEnterpricceIdVO', {}, function (res) {
            enterpriseInfo = res.data;
        }, 'get', false);

        //导出在用统计数据
        $('#useInventoryProductExport').click(function () {
            location.href = config.base + 'enterprisecab/cabinet/admin/useInventoryKnife/export?enterpriseCode='+enterpriseInfo.enterpriseCode;
        });

    });
</script>